/*
 * This file is part of SSHTTPD.
 *
 * SSHTTPD is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * SSHTTPD is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef _PLUGIN_H
#define _PLUGIN_H

/** @file
 * Defines global structures and functions implemented and used by plugin.c.
 */

/** Function pointer type for modules to provide for callbacks. */
typedef int(*callback_t)(char*);

/** modpack to be sent to new modules. */
typedef struct modpack {
	/** Function to callback in an event, assigned by module. */
        callback_t callback;         
	/** Destruction function pointer called when a module shutsdown. */
	void(*destruct)(void); 
        
	/** Provides a pointer to the event funtion to the module. */
	void(*event)(int, char*, ...); 	
	/** Same as above. */
	int(*callme)(callback_t);
	/** Pointer to the users module symbol. */
	void *modref; 
} modpack_t;

/** Stores module callback functions for now. */
extern callback_t callbacks[];

/**
 * Subscribes a function to the callback list, called by modules via a function pointer.
 * @param function The function to callback on an event.
 * @return 0 on success, other on fail. 
 */
int callme(callback_t function);

/* Stuff we dont want to expose to the module. */
#ifndef MODULE

/** Function pointer type for the modules init functions. */
typedef int(*mod_init)(modpack_t *modpack);

/**
 * Registers a module into the application.
 * @param path Path of the module on disk.
 * @return 0 on success, other on fail. 
 */
int cmod(const char *path);

/**
 * Unregisters a module from the system and destroys the modpack.
 * @param modpack Pointer to the modules modpack. 
 * @return 0 on success.
 */
int dcmod(modpack_t *modpack);
#endif

#endif
